﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

/// <summary>
/// Summary description for ResponseMessage
/// </summary>

[assembly: TagPrefix("Jalal.Library.Web.Control", "ucc")]
namespace Jalal.Library.Web.Control
{
    [SupportsEventValidation, ValidationProperty("Message")]
    [ToolboxData("<{0}:FieldValidationMessage runat=server></{0}:FieldValidationMessage>")]
    public class FieldValidationMessage : Literal
    {
        private string _message;
        public string Message
        {
            get { return this._message; }
            set { this._message = value; }
        }

        private string _failCssClass;
        public string FailCssClass
        {
            get { return this._failCssClass; }
            set { this._failCssClass = value; }
        }

        private string _successCssClass;
        public string SuccessCssClass
        {
            get { return this._successCssClass; }
            set { this._successCssClass = value; }
        }

        private string _initialCssClass;
        public string InitialCssClass
        {
            get { return this._initialCssClass; }
            set { this._initialCssClass = value; }
        }

        private string _failImageUrl = string.Empty;
        public string FailImageUrl
        {
            get { return this._failImageUrl.Replace("~/", string.Empty); }
            set { this._failImageUrl = value; }
        }

        private string _successImageUrl = string.Empty;
        public string SuccessImageUrl
        {
            get { return this._successImageUrl.Replace("~/",string.Empty); }
            set { this._successImageUrl = value; }
        }

        protected override void OnLoad(EventArgs e)
        { 
            if(string.IsNullOrEmpty(_message))
                this.Visible = false;
            base.OnLoad(e);
        }

        public void SetSuccessMessage(string message)
        {
            if (string.IsNullOrEmpty(SuccessImageUrl))
                SuccessImageUrl = "App_Themes/" + Page.Theme + "/image/tick.png";
            Message = message;
            this.Text = "<div class='" + SuccessCssClass + "'><image src='" + SuccessImageUrl + "' align='texttop' border-width='0px' /><span>" + message + "</span></div>";
            this.Visible = true;
        }

        public void SetInitialMessage(string message)
        {
            Message = message;
            this.Text = "<div class='" + InitialCssClass + "'><span>" + message + "</span></div>";
            this.Visible = true;
        }

        public void SetFailMessage(string message)
        {
            if (string.IsNullOrEmpty(FailImageUrl))
                FailImageUrl = "App_Themes/" + Page.Theme + "/image/cross.png";
            Message = message;
            this.Text = "<div class='" + FailCssClass + "'><image src='" + FailImageUrl + "' align='texttop' border-width='0px' /><span>" + message + "</span></div>";
            this.Visible = true;
        }
    }
}